package org.example.controller;

import org.example.exception.PermissionsDenyException;
import org.example.exception.SenderIdException;
import org.example.service.InvitationService;
import org.example.utils.R;
import org.example.vo.InvitationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("/invitation")
@Controller
public class InvitataionController {
    @Autowired
    InvitationService invitationService;

    @PostMapping("/sendInvitation")
    public @ResponseBody R sendInvitation(@RequestBody InvitationVo invitationVo) throws PermissionsDenyException, SenderIdException {
        invitationService.sendInvitation(invitationVo);
        return R.ok().setData(null);
    }

    @RequestMapping("/checkAllReceive")
    public @ResponseBody R checkAllReceive() {
        List<InvitationVo> invitationVos = invitationService.checkAllReceive();
        return R.ok().setData(invitationVos);
    }

    @RequestMapping("/receiveInvitation")
    public @ResponseBody R receiveInvitation(int invitationId) throws PermissionsDenyException {
        invitationService.receiveInvitation(invitationId);
        return R.ok().setData(null);
    }
}
